package design.mode.model.composite;

/**
 * @description 菜单项：属于叶子节点
 * @since jdk11
 */
public class MenuItem extends MenuComponent{

    public MenuItem(Builder builder) {
        this.id = builder.itemId;
        this.parentId = builder.itemParentId;
        this.name = builder.itemName;
        this.level = builder.itemLevel;
        this.url = builder.itemUrl;
        this.effective = builder.itemEffective;
    }

    @Override
    public void print() {
        for (int i = 0; i < level; i++) {
            System.out.print("--");
        }
    }

    public static final class Builder {
        protected String itemId;
        protected String itemParentId;
        protected String itemUrl;
        protected boolean itemEffective;
        /**
         * 菜单组件名称
         */
        protected String itemName;
        /**
         * 菜单组件层级
         */
        protected int itemLevel;

        public Builder id(String itemId) {
            this.itemId = itemId;
            return this;
        }

        public Builder parentId(String itemParentId) {
            this.itemParentId = itemParentId;
            return this;
        }

        public Builder url(String itemUrl) {
            this.itemUrl = itemUrl;
            return this;
        }

        public Builder menuName(String itemName) {
            this.itemName = itemName;
            return this;
        }

        public Builder effective(boolean itemEffective) {
            this.itemEffective = itemEffective;
            return this;
        }

        public Builder menuLevel(int itemLevel) {
            this.itemLevel = itemLevel;
            return this;
        }

        public MenuItem build() {
            return new MenuItem(this);
        }
    }

    @Override
    public String toString() {
        return "MenuItem{" +
                "id='" + id + '\'' +
                ", parentId='" + parentId + '\'' +
                ", url='" + url + '\'' +
                ", effective=" + effective +
                ", name='" + name + '\'' +
                ", level=" + level +
                '}';
    }
}
